#pragma once
#include "vector128.h"

struct L_LTF
{
  static const int SIZE   = 160 * 2 * sizeof(COMPLEX16);
  static const int COUNT  = 160 * 2;
  static const int VCOUNT = 160 * 2 / 4;
  static const int csd = 2;

  __forceinline void get_ltf_1(COMPLEX16* pout)
  {
    vcs *pvin  = reinterpret_cast<vcs*>(_ltf);
    vcs *pvout = reinterpret_cast<vcs*>(pout);

    for (int i = 0; i < VCOUNT; i++)
    {
      pvout[i] = pvin[i];
    }
  }

  __forceinline void get_ltf_2(COMPLEX16* pout)
  {
    vcs *pvin  = reinterpret_cast<vcs*>(_ltf);
    vcs *pvout = reinterpret_cast<vcs*>(pout);

    int i = 0;
    for (; i < 64; i++)
    {
      pvout[i + 16] = pvin[i + 16 - csd];
    }

    for (i = 0; i < 16; i++)
    {
      pvout[i] = pvout[80 - 16 + i];
    }
  }

  //////////////////////////////////////////////////////////////////////////
  __forceinline void get_ltf_1_of_4(COMPLEX16* pout)
  {
    vcs *pvin  = reinterpret_cast<vcs*>(_ltf);
    vcs *pvout = reinterpret_cast<vcs*>(pout);

    for (int i = 0; i < VCOUNT; i++)
    {
      pvout[i] = pvin[i];
    }
  }

  __forceinline void get_ltf_2_of_4(COMPLEX16* pout)
  {
    COMPLEX16 *pvin  = reinterpret_cast<COMPLEX16*>(_ltf);
    COMPLEX16 *pvout = reinterpret_cast<COMPLEX16*>(pout);
    static int const _csd = 2;

    int i = 0;
    for (; i < 256; i++)
    {
      pvout[i + 64] = pvin[i + 64 - _csd];
    }

    for (i = 0; i < 64; i++)
    {
      pvout[i] = pvout[320 - 64 + i];
    }
  }

  __forceinline void get_ltf_3_of_4(COMPLEX16* pout)
  {
    COMPLEX16 *pvin  = reinterpret_cast<COMPLEX16*>(_ltf);
    COMPLEX16 *pvout = reinterpret_cast<COMPLEX16*>(pout);
    static int const _csd = 4;

    int i = 0;
    for (; i < 256; i++)
    {
      pvout[i + 64] = pvin[i + 64 - _csd];
    }

    for (i = 0; i < 64; i++)
    {
      pvout[i] = pvout[320 - 64 + i];
    }
  }

  __forceinline void get_ltf_4_of_4(COMPLEX16* pout)
  {
    COMPLEX16 *pvin  = reinterpret_cast<COMPLEX16*>(_ltf);
    COMPLEX16 *pvout = reinterpret_cast<COMPLEX16*>(pout);
    static int const _csd = 6;

    int i = 0;
    for (; i < 256; i++)
    {
      pvout[i + 64] = pvin[i + 64 - _csd];
    }

    for (i = 0; i < 64; i++)
    {
      pvout[i] = pvout[320 - 64 + i];
    }
  }
private:
  static A16 COMPLEX16 _ltf[160 * 2];
};

SELECTANY COMPLEX16 L_LTF::_ltf[] =
{
    {-2460, 0},{-1636, -944},{193, -1536},{1588, -1700},{1444, -1667},{-38, -1710},{-1447, -1812},{-1435, -1626},{-44, -847},{1294, 320},{1182, 1166},{-358, 1099},{-2004, 323},{-2537, -219},{-1919, 261},{-1014, 1513},
    {-552, 2375},{-607, 1897},{-889, 343},{-1104, -1038},{-949, -1280},{-152, -643},{1095, -222},{1886, -659},{1294, -1454},{-494, -1647},{-2066, -1027},{-2136, -411},{-901, -619},{287, -1378},{581, -1548},{513, -495},
    {984, 984},{1807, 1365},{1877, 64},{789, -1811},{-354, -2529},{-231, -1492},{924, 235},{1469, 1158},{385, 921},{-1410, 469},{-2154, 746},{-1312, 1539},{16, 1810},{692, 1043},{840, -64},{1167, -369},
    {1536, 408},{1008, 1406},{-603, 1671},{-2009, 1221},{-1812, 869},{-278, 1094},{942, 1381},{874, 877},{332, -439},{599, -1522},{1524, -1303},{1722, 165},{626, 1750},{-490, 2368},{-81, 1894},{1544, 944},
    {2460, 0},{1544, -944},{-81, -1894},{-490, -2368},{626, -1750},{1722, -165},{1524, 1303},{599, 1522},{332, 439},{874, -877},{942, -1381},{-278, -1094},{-1812, -869},{-2009, -1221},{-603, -1671},{1008, -1406},
    {1536, -408},{1167, 369},{840, 64},{692, -1043},{16, -1810},{-1312, -1539},{-2154, -746},{-1410, -469},{385, -921},{1469, -1158},{924, -235},{-231, 1492},{-354, 2529},{789, 1811},{1877, -64},{1807, -1365},
    {984, -984},{513, 495},{581, 1548},{287, 1378},{-901, 619},{-2136, 411},{-2066, 1027},{-494, 1647},{1294, 1454},{1886, 659},{1095, 222},{-152, 643},{-949, 1280},{-1104, 1038},{-889, -343},{-607, -1897},
    {-552, -2375},{-1014, -1513},{-1919, -261},{-2537, 219},{-2004, -323},{-358, -1099},{1182, -1166},{1294, -320},{-44, 847},{-1435, 1626},{-1447, 1812},{-38, 1710},{1444, 1667},{1588, 1700},{193, 1536},{-1636, 944},
    {-2460, 0},{-1636, -944},{193, -1536},{1588, -1700},{1444, -1667},{-38, -1710},{-1447, -1812},{-1435, -1626},{-44, -847},{1294, 320},{1182, 1166},{-358, 1099},{-2004, 323},{-2537, -219},{-1919, 261},{-1014, 1513},
    {-552, 2375},{-607, 1897},{-889, 343},{-1104, -1038},{-949, -1280},{-152, -643},{1095, -222},{1886, -659},{1294, -1454},{-494, -1647},{-2066, -1027},{-2136, -411},{-901, -619},{287, -1378},{581, -1548},{513, -495},
    {984, 984},{1807, 1365},{1877, 64},{789, -1811},{-354, -2529},{-231, -1492},{924, 235},{1469, 1158},{385, 921},{-1410, 469},{-2154, 746},{-1312, 1539},{16, 1810},{692, 1043},{840, -64},{1167, -369},
    {1536, 408},{1008, 1406},{-603, 1671},{-2009, 1221},{-1812, 869},{-278, 1094},{942, 1381},{874, 877},{332, -439},{599, -1522},{1524, -1303},{1722, 165},{626, 1750},{-490, 2368},{-81, 1894},{1544, 944},
    {2460, 0},{1544, -944},{-81, -1894},{-490, -2368},{626, -1750},{1722, -165},{1524, 1303},{599, 1522},{332, 439},{874, -877},{942, -1381},{-278, -1094},{-1812, -869},{-2009, -1221},{-603, -1671},{1008, -1406},
    {1536, -408},{1167, 369},{840, 64},{692, -1043},{16, -1810},{-1312, -1539},{-2154, -746},{-1410, -469},{385, -921},{1469, -1158},{924, -235},{-231, 1492},{-354, 2529},{789, 1811},{1877, -64},{1807, -1365},
    {984, -984},{513, 495},{581, 1548},{287, 1378},{-901, 619},{-2136, 411},{-2066, 1027},{-494, 1647},{1294, 1454},{1886, 659},{1095, 222},{-152, 643},{-949, 1280},{-1104, 1038},{-889, -343},{-607, -1897},
    {-552, -2375},{-1014, -1513},{-1919, -261},{-2537, 219},{-2004, -323},{-358, -1099},{1182, -1166},{1294, -320},{-44, 847},{-1435, 1626},{-1447, 1812},{-38, 1710},{1444, 1667},{1588, 1700},{193, 1536},{-1636, 944},
    {-2460, 0},{-1636, -944},{193, -1536},{1588, -1700},{1444, -1667},{-38, -1710},{-1447, -1812},{-1435, -1626},{-44, -847},{1294, 320},{1182, 1166},{-358, 1099},{-2004, 323},{-2537, -219},{-1919, 261},{-1014, 1513},
    {-552, 2375},{-607, 1897},{-889, 343},{-1104, -1038},{-949, -1280},{-152, -643},{1095, -222},{1886, -659},{1294, -1454},{-494, -1647},{-2066, -1027},{-2136, -411},{-901, -619},{287, -1378},{581, -1548},{513, -495},
    {984, 984},{1807, 1365},{1877, 64},{789, -1811},{-354, -2529},{-231, -1492},{924, 235},{1469, 1158},{385, 921},{-1410, 469},{-2154, 746},{-1312, 1539},{16, 1810},{692, 1043},{840, -64},{1167, -369},
    {1536, 408},{1008, 1406},{-603, 1671},{-2009, 1221},{-1812, 869},{-278, 1094},{942, 1381},{874, 877},{332, -439},{599, -1522},{1524, -1303},{1722, 165},{626, 1750},{-490, 2368},{-81, 1894},{1544, 944},
};
